/**
 * 
 */
package com.sony.csl.positioning.publictransport.model;

import java.util.Vector;

import javax.microedition.location.Coordinates;
import javax.microedition.location.Location;
import javax.microedition.location.LocationProvider;

import com.sony.csl.j2me.locationapitools.LocationProxy;
import com.sony.csl.j2me.locationapitools.LocationProxyListener;
import com.sony.csl.j2me.util.Logger;
import com.sony.csl.positioning.publictransport.model.network.PublicTransportNetwork;


/**
 * @author mstevens
 *
 */
public class World implements LocationProxyListener
{

	//STATIC-------------------------------------------------------
	static public final boolean KEEP_FULL_HISTORY = false;
	
	static private World INSTANCE = null;
	
    /**
     * Provide singleton instance of this class.
     * 
     * @return static instance of this class.
     */
    static public World getInstance()
    {
    	try
    	{
    		if(INSTANCE == null)
    			INSTANCE = new World();
    		return INSTANCE;
    	}
    	catch(Exception e)
    	{
    		Logger.logLine("Exception: Could not create World instance (" + e.getMessage() +").");
    		return null;
    	}
    }
	
	//DYNAMIC------------------------------------------------------
	private Vector POIs;
	private PublicTransportNetwork publicTransportNetwork;
	private Coordinates lastKnownPosition;
	

	private World()
	{
		super();
		this.POIs = new Vector();
	}
	
	/**
	 * @return the POIs
	 */
	public Vector getPOIs()
	{
		return POIs;
	}
	
	public void addPOI(POI poi)
	{
		this.POIs.addElement(poi);
	}
	
	/**
	 * @return the publicTransportNetwork
	 */
	public PublicTransportNetwork getPublicTransportNetwork()
	{
		return publicTransportNetwork;
	}
	
	/**
	 * @param publicTransportNetwork the publicTransportNetwork to set
	 */
	public void setPublicTransportNetwork(PublicTransportNetwork publicTransportNetwork)
	{
		this.publicTransportNetwork = publicTransportNetwork;
	}
	
	/**
	 * @return the lastKnownPosition
	 */
	public Coordinates getLastKnownPosition()
	{
		return lastKnownPosition;
	}

	/**
	 * @param lastKnownPosition the lastKnownPosition to set
	 */
	public void setLastKnownPosition(Coordinates lastKnownPosition)
	{
		if(lastKnownPosition != null)
			this.lastKnownPosition = lastKnownPosition;
	}

	public void firstLocationFound(LocationProxy proxy, LocationProvider provider, Location location) {}

	public void locationProviderStateChanged(LocationProxy proxy, LocationProvider provider, int newState) {}

	public void locationUpdated(LocationProxy proxy, LocationProvider provider,	Location location)
	{
		if(location.isValid())
			setLastKnownPosition(location.getQualifiedCoordinates());
	}

	public void proxyConnected(LocationProxy proxy, LocationProvider provider) {}

	public void proxyDisconnected(LocationProxy proxy) {}

	public boolean receivesInvalidLocations()
	{
		return false;
	}

}
